﻿<%@ Page Language="C#" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data" %>
<%    OleDbConnection conn = null;
     
          
          
          string limit = Request.Params["limit"];
          string start = Request.Params["start"];
          string where = Request.Params["where"];
          try {
              int min = 0;              
              min = int.Parse(start);
              int interval = 0;
              interval = int.Parse(limit);              
              min = min < 0 ? 0 : min;
              interval = interval < 0 ? 0 : interval;
              int max = 0;
              max = min + interval;
              //string where = " a.街道名 = '清波街道' ";              
              where = string.IsNullOrEmpty(where) ? "" : where;
              where = string.IsNullOrEmpty(where.Trim()) ? "" : " where " + where.Trim() + " ";
              if (string.IsNullOrEmpty(where))
              {
                  where = " where Point_X is not null";
              }
              else
              {
                  where += " and Point_X is not null";
              }
              try
              {
                  conn = DBOp.DbConn;

                  OleDbCommand commandtotal = conn.CreateCommand();
                  commandtotal.CommandText = "select count(*) from jz " + where;
                  DataTable dttotal = new DataTable();
                  OleDbDataAdapter odatotal = new OleDbDataAdapter(commandtotal);
                  odatotal.Fill(dttotal);
                  string totalcounts = dttotal.Rows[0][0].ToString();
              %>
    {"totalcount":"<%=totalcounts%>",
    "root":<%
    if (totalcounts == "0" || totalcounts == null || totalcounts == "")
    { 
                  %>[]}<%
    }
    else
    {
        OleDbCommand comm = conn.CreateCommand();
        string querycols = " 建筑统一编码, 城区名称, 街道名, 社区名, int(建筑投影面积) as 建筑投影面积, int(建筑面积) as 建筑面积, 建筑层数, 建筑类型, 建筑功能, 建造年代, 建筑结构, 屋顶形式, 玻璃幕墙, 电梯数, 空调数, 户数, 太阳能利用, 空调类型, 空调开启时间段, 建筑年代, 空调系统类型, 制热量, 地下室功能, 地下室层数, 地下室面积, 制冷量, 节能建筑, 节能改造, 单元数, 建筑地址, 楼幢号, 建筑名称, 备注,POINT_X,POINT_Y,建筑年单位面积能耗";
        if (min == 0)
        {
            comm.CommandText = "select top " + max + querycols + " from jz"
                              +  where;
        }
        else
        {
            comm.CommandText = "select a.* from ( select top " + max + querycols + " from jz j1 " + where + " ) a "
                              + " left join ( select top " + min + querycols + " from jz j2 " + where + " ) b "
                              + " on a.建筑统一编码=b.建筑统一编码 "
                              + " where iif(b.建筑统一编码,'0','1')='1' ";
        }

        DataTable dt = new DataTable();
        OleDbDataAdapter oda = new OleDbDataAdapter(comm);
        oda.Fill(dt);
                  %>
    <%Response.Write(JSONUtility.CreateJsonParameters(dt));%>}<%
    }
              }
              catch (Exception e) { %>[]}<%}
              
          }
          catch (Exception e) { }
          
    
    finally{              
    if(conn != null)
    conn.Close();} %>